#include<bits/stdc++.h>
#define ll long long
#define L x<<1
#define R L|1
#define mid (l+r>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define OK Ll<=l&&r<=Rr
#define Root 1,1,n
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<ll,ll>
#define ui unsigned ll
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N=1e6+5,M=1.1e6+5,inf=(1LL<<31)-1,mod=998244353;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,int b){if(!b)return 1;int c=qp(a,b>>1);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
int n,p[N],Mx=19;
ll k;
inline void sub1(){
    repn(i)p[i]=i;
    do{
        bool fl=1;
        int sum=0;
        rep(i,1,n-1){
            sum+=p[i];
            if(sum<=p[i+1])fl=0;
        }
        if(fl)k--;
        if(!k){
            repn(i)cout <<p[i]<<' ';
            return;
        }
    }while(next_permutation(p+1,p+n+1));
}
ll fac[N];
int xd[N<<2];
inline void build(int x,int l,int r){
    xd[x]=r-l+1;
    if(l^r)build(lc),build(rc);
}
inline void del(int x,int l,int r,int p){
    xd[x]--;
    if(l^r)p<=mid?del(lc,p):del(rc,p);
}
inline int query(int x,int l,int r,int k){
    if(l==r)return l;
    return xd[L]>=k?query(lc,k):query(rc,k-xd[L]);
}
inline void Get(int n){
    fac[0]=1;
    rep(i,1,Mx)fac[i]=fac[i-1]*i;
    build(Root);
    repn(i){
        if(n-i>Mx){
            del(Root,i),p[i]=i;
        }else{
            ll K=fac[n-i];
            ll w=(k+K-1)/K;
            p[i]=query(Root,w),del(Root,p[i]);
            if(w*K==k)k=K;
            else k%=K;
        }
    }
}
bool vis[N];
int a[N];
vector<int>d;
inline void dfs(int pos,int sum){
    if(sum>n){
        int dis=n-pos+1;
        if(dis>Mx){
            d.pb(0);
            repn(i)if(!vis[i])d.pb(i);
            rep(i,1,pos-1)cout <<a[i]<<" ";
            Get(n-pos+1);
            rep(i,1,n-pos+1)cout <<d[p[i]]<<" ";
            exit(0);
        }
        if(fac[dis]>=k){
            d.pb(0);
            repn(i)if(!vis[i])d.pb(i);
            rep(i,1,pos-1)cout <<a[i]<<" ";
            Get(n-pos+1);
            rep(i,1,n-pos+1)cout <<d[p[i]]<<' ';
            exit(0);
        }else k-=fac[dis];
        return;
    }
    rep(i,1,sum-1)if(!vis[i])vis[i]=1,a[pos]=i,dfs(pos+1,sum+i),vis[i]=0;
}
inline void Main(){
    cin>>n>>k;
    if(n<=8)return sub1(),void();
    if(k==1){
        cout <<"3 1 2 ";
        rep(i,4,n)cout <<i<<' ';
        return;
    }
    if(k==2){
        cout <<"3 1 2 ";
        rep(i,4,n-2)cout <<i<<' ';
        cout <<n-1<<' '<<n-2;
        return;
    }
    int Nw=6;
    rep(i,4,n){
        Nw+=i;
        if(Nw>n){
            int dis=n-i;
            if(dis>=Mx){
                Get(dis);
                cout <<"3 1 2 ";
                rep(j,4,i)cout <<j<<' ';
                rep(j,1,dis)cout <<i+p[j]<<' ';
                return;
            }
            break;
        }
    }
    fac[0]=1;
    rep(i,1,Mx)fac[i]=fac[i-1]*i;
    rep(i,3,n)vis[i]=1,a[1]=i,dfs(2,i),vis[i]=0;
}
signed main(){
	freopen("permutation.in","r",stdin);
	freopen("permutation.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}	